/**
 * 机器管理路由
 *
 * Created by raquelmao on 2020/07/21.
 */
const middleware = require('./../middleware');
const machine = require('./../../models/machine');
const PhoenixError = require('./../../models/phoenix-error');

/**
 * 获取编译配置选项
 * @param req
 * @param res
 * @param next
 */
function getCompilationOptions(req, res, next) {
  machine.getCompilationOptions()
    .then((projectTypes) => {
      res.json(projectTypes);
    })
    .catch((err) => {
      next(new PhoenixError(err));
    });
}

/**
 * Export model definition object.
 */
module.exports = (app, prefix) => {
  const compilationOptionsURL = `${prefix}/machine/compilation-options.json`;

  // 获取编译配置选项
  app.get(compilationOptionsURL, middleware.user.requireTokenUnexpired);
  app.get(compilationOptionsURL, middleware.user.requireAvailable);
  app.get(compilationOptionsURL, middleware.user.requireTester);
  app.get(compilationOptionsURL, getCompilationOptions);
};
